/**
 * 
 * 起迪科技 Copyright (c) 2014-2018 QiDi,Inc.All Rights Reserved.
 */
package cn.qidisoft.edu.hzjt.controller.Semester;

import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;

import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.core.util.DateUtil;
import cn.qidisoft.core.util.StringUtils;
import cn.qidisoft.core.util.moffice.excel.ExpExcelUtil;
import cn.qidisoft.core.util.uuid.UUIDGenerator;
import cn.qidisoft.core.web.customargument.bind.annotation.Token;
import cn.qidisoft.edu.hzjt.annotation.SysLogger;
import cn.qidisoft.edu.hzjt.constants.Constant;
import cn.qidisoft.edu.hzjt.controller.BaseController;
import cn.qidisoft.edu.hzjt.model.Grade;
import cn.qidisoft.edu.hzjt.model.RecommendStudent;
import cn.qidisoft.edu.hzjt.model.ResponseResult;
import cn.qidisoft.edu.hzjt.model.Semester;
import cn.qidisoft.edu.hzjt.model.SemesterSummary;
import cn.qidisoft.edu.hzjt.model.Student;
import cn.qidisoft.edu.hzjt.model.StudentClass;
import cn.qidisoft.edu.hzjt.model.UserEmployee;
import cn.qidisoft.edu.hzjt.service.ICommonService;
import cn.qidisoft.edu.hzjt.service.IRecommendStudentService;
import cn.qidisoft.edu.hzjt.service.ISemesterSummaryService;
import cn.qidisoft.edu.hzjt.utils.LogType;
import cn.qidisoft.edu.hzjt.vo.RecommendStudentBean;

/**
 * 
 * @author hxq
 * @version $Id: SemesterSummaryController.java, v 0.1 2018年10月29日 下午1:26:31 hxq Exp $
 */
@Controller
@RequestMapping("semesterSummary")
public class SemesterSummaryController {
  protected static final LoggerAdapter LOGGER =
      LoggerAdapterFactory.getLogger(LogType.HZJT_LOGGER.val);
  @Autowired
  private ISemesterSummaryService semesterSummaryService;
  @Autowired
  private ICommonService commonService;
  @Autowired
  private IRecommendStudentService recommendStudentService;

  /**
   * 学生期末总结 列表页面跳转页面(学生端)
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/semesterSummaryIndex")
  public String index(ModelMap model, HttpServletRequest request) {
    try {
      request.setAttribute("msg", BaseController.getParameter("msg"));
      BaseController.removeParameter("msg");
      BaseController.getSemesterList(model, commonService);
      BaseController.getSemester(model, commonService);
      BaseController.getCodeList(model, commonService, Constant.ZZMM_CODE);
    } catch (Exception e) {
      LOGGER.error("获得学生期末总结列表信息 index [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return "semesterSummary/semesterSummary_list";
  }

  /**
   * 学生期末总结列表(学生端)
   * 
   * @param model
   * @param request
   * @param pageSize
   * @param currentPage
   * @param data
   * @return
   */
  @RequestMapping(value = "/semesterSummaryList")
  @ResponseBody
  public ResponseResult semesterSummaryList(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "rows", required = false) String pageSize,
      @RequestParam(value = "page", required = false) String currentPage, SemesterSummary data) {
    ResponseResult result = new ResponseResult();
    try {
      Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
      if (loginType == 1) { // 学生
        Student student = (Student) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        Page page = BaseController.getPage(currentPage, pageSize, request, "createtime", "desc");
        data.setStuid(student.getXsid());
        data.setOrderField((String) request.getAttribute("orderField"));
        data.setOrderFlag((String) request.getAttribute("orderFlag"));
        PaginationBean<SemesterSummary> paginationBean =
            semesterSummaryService.querySemesterSummaryPageList(data, page);
        result.setTotal(paginationBean.getTotalRecords());
        if (paginationBean.getPageList().isEmpty()) {
          result.setRows(new ArrayList<SemesterSummary>());
        } else {
          result.setRows(paginationBean.getPageList());
        }
      } else {
        result.setRows(new ArrayList<SemesterSummary>());
        result.setTotal(0);
      }
      return result;
    } catch (Exception e) {
      result.setRows(new ArrayList<SemesterSummary>());
      result.setTotal(0);
      e.printStackTrace();
      LOGGER.error(
          "获得学生期末总结列表信息 semesterSummaryList [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());

    }
    return result;
  }

  /**
   * 学生期末总结(学生端)新增页面跳转
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/addSemesterSummaryForward")
  @Token(save = true)
  public String addSemesterSummaryForward(ModelMap model, HttpServletRequest request) {
    try {
      Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
      if (loginType == 1) { // 学生
        Student student = (Student) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        // 获取标准信息
        BaseController.getSemesterList(model, commonService);
        BaseController.getSemester(model, commonService);
        BaseController.getCodeList(model, commonService, Constant.ZZMM_CODE);
        model.put("student", student);
        model.put("msg", BaseController.getParameter("msg"));
        BaseController.removeParameter("msg");
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:semesterSummaryIndex";
      }
    } catch (Exception e) {
      LOGGER.error(
          "获得学生期末总结信息 addSemesterSummaryForward [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return "semesterSummary/addSemesterSummary";
  }

  /**
   * 学生期末总结(学生端)保存功能
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/addSemesterSummary")
  @Token(remove = true, path = "semesterSummaryIndex")
  @SysLogger(description = "学生新增学生期末总结信息", moduleName = "学生期末总结信息", method = "新增")
  public String addSemesterSummary(ModelMap model, HttpServletRequest request,
      SemesterSummary semesterSummary) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      if (loginType == 1) { // 学生
        Student student = (Student) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        semesterSummary.setGid(UUIDGenerator.genReqID());
        semesterSummary.setStuid(student.getXsid());
        semesterSummary.setCreatetime(new Date());
        String p1 = request.getParameter("p");
        String p21 = request.getParameter("p21");
        String p22 = request.getParameter("p22");
        String sqxm = "";
        if (!StringUtils.isNullValue(p1)) {
          sqxm = sqxm + p1 + ",";
        }
        if (!StringUtils.isNullValue(p21)) {
          sqxm = sqxm + p21 + ",";
        }
        if (!StringUtils.isNullValue(p22)) {
          sqxm = sqxm + p22 + ",";
        }
        if (!StringUtils.isNullValue(sqxm)) {
          sqxm = sqxm.trim().substring(0, sqxm.trim().length() - 1);
        }
        semesterSummary.setBjid(student.getBjid());
        semesterSummary.setSqxm(sqxm);
        int zjjid = semesterSummaryService.addSemesterSummary(semesterSummary);
        String flag = request.getParameter("flag");
        if (zjjid >= 1 && !StringUtils.isNullValue(flag) && "1".equals(flag)) { // 新增跳转到修改页面
          // 根据guid获得zjid信息
          // semesterSummary = semesterSummaryService.queryGuidBySemesterSummary(semesterSummary);
          BaseController.setParameter("msg", "保存成功");
          return "redirect:modiftySemesterSummaryForward?zjid=" + zjjid;
        } else if (zjjid >= 1 && !StringUtils.isNullValue(flag) && "2".equals(flag)) { // 新增且继续新增
          BaseController.setParameter("msg", "保存成功");
          return "redirect:addSemesterSummaryForward";
        } else {
          BaseController.setParameter("msg", "保存失败");
          return "redirect:semesterSummaryIndex";
        }
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:semesterSummaryIndex";
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "新增学生期末总结信息 addSemesterSummary [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
  }

  /**
   * 
   * 学生期末总结(学生端) 修改跳转页面
   * 
   * @param model
   * @param request
   * @param id
   * @return
   */
  @RequestMapping(value = "/modiftySemesterSummaryForward", method = RequestMethod.GET)
  public String modiftySemesterSummaryForward(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "zjid") Integer id) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      if (loginType == 1) { // 学生
        Student student = (Student) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        // 获取标准信息
        BaseController.getSemesterList(model, commonService);
        BaseController.getSemester(model, commonService);
        BaseController.getCodeList(model, commonService, Constant.ZZMM_CODE);
        model.put("student", student);
        if (id != null) {
          SemesterSummary semesterSummary = semesterSummaryService.queryByPK(id);
          String p1 = null, p2 = null, p3 = null, p21 = null, p22 = null;
          if (!StringUtils.isNullValue(semesterSummary.getSqxm())) {
            String[] SqxmArr = semesterSummary.getSqxm().split(",");
            for (String i : SqxmArr) {
              switch (i) {
                case Constant.PXXM_TYPE1:
                  p1 = i;
                  break;
                case Constant.PXXM_TYPE2:
                  p2 = i;
                  break;
                case Constant.PXXM_TYPE3:
                  p3 = i;
                  break;
                case Constant.PXXM_TYPE4:
                  p21 = i;

                  break;
                case Constant.PXXM_TYPE5:
                  p22 = i;
                  break;
                default:
                  break;
              }
            }
            model.put("p1", p1);
            model.put("p2", p2);
            model.put("p3", p3);
            model.put("p21", p21);
            model.put("p22", p22);
            model.put("semesterSummary", semesterSummary);
            model.put("msg", BaseController.getParameter("msg"));
            BaseController.removeParameter("msg");
            return "semesterSummary/editSemesterSummary";
          }
        }
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:semesterSummaryIndex";
      }
    } catch (Exception e) {
      LOGGER.error("修改学生期末总结信息 modiftySemesterSummaryForward [{}] error,"
          + this.getClass().getName() + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return "redirect:semesterSummaryIndex";
  }


  /**
   * 
   * 学生期末总结(学生端) 修改
   * 
   * @param model
   * @param request
   * @param SemesterSummary
   * @return
   */
  @RequestMapping(value = "/modiftySemesterSummary")
  @SysLogger(description = "学生修改学生期末总结信息", moduleName = "学生期末总结信息", method = "修改")
  public String modiftySemesterSummary(ModelMap model, HttpServletRequest request,
      SemesterSummary SemesterSummary) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      if (loginType == 1) { // 学生
        Student student = (Student) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        String p = request.getParameter("p");
        String p21 = request.getParameter("p21");
        String p22 = request.getParameter("p22");
        String sqxm = "";
        if (!StringUtils.isNullValue(p)) {
          sqxm = sqxm + p + ",";
        }
        if (!StringUtils.isNullValue(p21)) {
          sqxm = sqxm + p21 + ",";
        }
        if (!StringUtils.isNullValue(p22)) {
          sqxm = sqxm + p22 + ",";
        }
        if (!StringUtils.isNullValue(sqxm)) {
          sqxm = sqxm.trim().substring(0, sqxm.trim().length() - 1);
        }
        SemesterSummary.setBjid(student.getBjid());
        SemesterSummary.setSqxm(sqxm);
        int num = semesterSummaryService.modiftySemesterSummary(SemesterSummary);
        if (num >= 1) {
          BaseController.setParameter("msg", "保存成功");
        } else {
          BaseController.setParameter("msg", "保存失败");
        }

      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:semesterSummaryIndex";
      }
    } catch (Exception e) {
      LOGGER.error(
          "修改学生期末总结信息 modiftySemesterSummary [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return "redirect:modiftySemesterSummaryForward?zjid=" + SemesterSummary.getZjid();

  }

  /**
   * 学生删除末总结信息(学生端)
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/removeSemesterSummary", method = RequestMethod.POST)
  @SysLogger(description = "学生删除学生期末总结信息", moduleName = "学生期末总结信息", method = "删除")
  public String removeSemesterSummary(ModelMap model, HttpServletRequest request) {
    try {
      String[] idList = request.getParameter("idList").split(",");
      if (idList.length >= 1) {
        int num = semesterSummaryService.deleteSemesterSummary(idList);
        if (num >= 1) {
          BaseController.setParameter("msg", "删除成功");
        } else {
          BaseController.setParameter("msg", "删除失败");
        }
      }
      return "redirect:semesterSummaryIndex";
    } catch (Exception e) {
      LOGGER.error(
          "删除学生期末总结信息 removeSemesterSummary [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
  }

  /**
   * 学生期末总结 列表页面跳转页面(管理端)
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/semesterSummaryManagerIndex")
  public String managerIndex(ModelMap model, HttpServletRequest request) {
    try {
      Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
      if (loginType == 2) { // 老师
        request.setAttribute("msg", BaseController.getParameter("msg"));
        BaseController.removeParameter("msg");
        // 获得标准信息
        BaseController.getSemesterList(model, commonService);
        BaseController.getSemester(model, commonService);
        BaseController.getCodeList(model, commonService, Constant.ZZMM_CODE);
        // 获得年级信息
        BaseController.getGradeList(model, commonService);
        // 获得专业
        BaseController.getSpecialityList(model, commonService);
        // Student student = new Student();
        // List<Grade> gradeList = (List<Grade>) model.get("gradeList");
        // if (!gradeList.isEmpty()) {
        // student.setNjid(gradeList.get(0).getNjid());
        // request.getSession().setAttribute("gradeid", gradeList.get(0).getNjid());
        // }

        BaseController.getClassListAndBzrid(request, model, commonService, loginType);
        // } else {
        // request.setAttribute("msg", BaseController.getParameter("msg"));
        // }
      }

    } catch (Exception e) {
      LOGGER.error("学生期末总结信息管理端列表 managerIndex [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }

    return "semesterSummary/semesterSummary_manager_list";
  }

  /**
   * 学生期末总结列表(管理端)
   * 
   * @param model
   * @param request
   * @param pageSize
   * @param currentPage
   * @param data
   * @return
   */
  @RequestMapping(value = "/semesterSummaryManagerList")
  @ResponseBody
  public ResponseResult semesterSummaryManagerList(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "rows", required = false) String pageSize,
      @RequestParam(value = "page", required = false) String currentPage, SemesterSummary data) {
    ResponseResult result = new ResponseResult();
    try {
      Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
      String ismanager = request.getParameter("bzr");
      if (loginType == 2) { // 老师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        Page page = BaseController.getPage(currentPage, pageSize, request, "xh", "asc");
        data.setIsmanager(Integer.parseInt(ismanager));
        data.setBzrid(userEmployee.getEmid());
        // if (data.getNjid() == null) {
        // data.setNjid((Integer) request.getSession().getAttribute("gradeid"));
        // }
        data.setOrderField((String) request.getAttribute("orderField"));
        data.setOrderFlag((String) request.getAttribute("orderFlag"));
        PaginationBean<SemesterSummary> paginationBean =
            semesterSummaryService.querySemesterSummaryPageManagerList(data, page);
        if (paginationBean.getPageList().isEmpty()) {
          result.setRows(new ArrayList<SemesterSummary>());
        } else {
          result.setRows(paginationBean.getPageList());
        }
        result.setTotal(paginationBean.getTotalRecords());
      } else {
        result.setRows(new ArrayList<SemesterSummary>());
        result.setTotal(0);
      }
      return result;
    } catch (Exception e) {
      result.setRows(new ArrayList<SemesterSummary>());
      result.setTotal(0);
      e.printStackTrace();
      LOGGER.error("获得学生期末总结列表信息(管理端) semesterSummaryManagerList [{}] error,"
          + this.getClass().getName() + "=[{}]", this.getClass().getName(), e.getMessage());
    }
    return result;
  }

  /**
   * 学生期末总结(管理端)新增页面跳转
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/addSemesterSummaryManagerForward")
  @Token(save = true)
  public String addSemesterSummaryManagerForward(ModelMap model, HttpServletRequest request) {
    String ismanager = request.getParameter("ismanager");
    try {
      Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
      if (loginType == 2) { // 老师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);

        List<Student> studentList = null;
        if (!StringUtils.isNullValue(ismanager) && Constant.IS_BZR.equals(ismanager)) {
          StudentClass stuClass = new StudentClass();
          stuClass.setBzrid(userEmployee.getEmid());
          studentList = commonService.queryClassOrGradeByStudent(stuClass);
        } else {
          studentList = commonService.queryClassOrGradeByStudent(null);
        }
        // 获得标准信息
        BaseController.getSemesterList(model, commonService);
        BaseController.getSemester(model, commonService);
        BaseController.getCodeList(model, commonService, Constant.ZZMM_CODE);
        model.put("studentList", studentList);
        model.put("studentListJson", JSON.toJSONString(studentList));
        model.put("ismanager", ismanager);
        model.put("msg", BaseController.getParameter("msg"));
        BaseController.removeParameter("msg");
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:semesterSummaryManagerIndex?bzr=" + ismanager;
      }
    } catch (Exception e) {
      LOGGER.error("获得学生期末总结信息(管理端) addSemesterSummaryManagerForward [{}] error,"
          + this.getClass().getName() + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return "semesterSummary/addManagerSemesterSummary";
  }

  /**
   * 学生期末总结(管理端)保存功能
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/addManagerSemesterSummary")
  @Token(remove = true, path = "semesterSummaryManagerIndex")
  @SysLogger(description = "学生新增学生期末总结信息", moduleName = "学生期末总结信息", method = "新增")
  public String addManagerSemesterSummary(ModelMap model, HttpServletRequest request,
      SemesterSummary semesterSummary) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      if (loginType == 2) { // 老师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        semesterSummary.setGid(UUIDGenerator.genReqID());
        // semesterSummary.setStuid(student.getXsid());
        semesterSummary.setCreatetime(new Date());
        String p1 = request.getParameter("p");
        String p21 = request.getParameter("p21");
        String p22 = request.getParameter("p22");
        String sqxm = "";
        if (!StringUtils.isNullValue(p1)) {
          sqxm = sqxm + p1 + ",";
        }
        if (!StringUtils.isNullValue(p21)) {
          sqxm = sqxm + p21 + ",";
        }
        if (!StringUtils.isNullValue(p22)) {
          sqxm = sqxm + p22 + ",";
        }
        if (!StringUtils.isNullValue(sqxm)) {
          sqxm = sqxm.trim().substring(0, sqxm.trim().length() - 1);
        }
        // semesterSummary.setBjid(student.getBjid());
        semesterSummary.setSqxm(sqxm);
        int zjjid = semesterSummaryService.addSemesterSummary(semesterSummary);
        String flag = request.getParameter("flag");
        if (zjjid >= 1 && !StringUtils.isNullValue(flag) && "1".equals(flag)) { // 新增跳转到修改页面
          // 根据guid获得zjid信息
          // semesterSummary = semesterSummaryService.queryGuidBySemesterSummary(semesterSummary);
          BaseController.setParameter("msg", "保存成功");
          return "redirect:modiftySemesterSummaryManagerForward?zjid=" + zjjid + "&ismanager="
              + request.getParameter("ismanager");
        } else if (zjjid >= 1 && !StringUtils.isNullValue(flag) && "2".equals(flag)) { // 新增且继续新增
          BaseController.setParameter("msg", "保存成功");
          return "redirect:addSemesterSummaryManagerForward?ismanager="
              + request.getParameter("ismanager");
        } else {
          BaseController.setParameter("msg", "保存失败");
          return "redirect:semesterSummaryManagerIndex?bzr=" + request.getParameter("ismanager");
        }
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:semesterSummaryManagerIndex?bzr=" + request.getParameter("ismanager");
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "新增学生期末总结信息 addManagerSemesterSummary [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
  }

  /**
   * 
   * 学生期末总结(管理端) 修改跳转页面
   * 
   * @param model
   * @param request
   * @param id
   * @return
   */
  @RequestMapping(value = "/modiftySemesterSummaryManagerForward", method = RequestMethod.GET)
  public String modiftySemesterSummaryManagerForward(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "zjid") Integer id) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    String ismanager = request.getParameter("ismanager");
    try {
      if (loginType == 2) { // 老师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);

        List<Student> studentList = null;
        if (!StringUtils.isNullValue(ismanager) && Constant.IS_BZR.equals(ismanager)) {
          StudentClass stuClass = new StudentClass();
          stuClass.setBzrid(userEmployee.getEmid());
          studentList = commonService.queryClassOrGradeByStudent(stuClass);
        } else {
          studentList = commonService.queryClassOrGradeByStudent(null);
        }
        // 获取标准信息
        BaseController.getSemesterList(model, commonService);
        BaseController.getSemester(model, commonService);
        BaseController.getCodeList(model, commonService, Constant.ZZMM_CODE);
        model.put("studentList", studentList);
        model.put("studentListJson", JSON.toJSONString(studentList));
        model.put("ismanager", ismanager);
        Student student = new Student();
        if (id != null) {
          SemesterSummary semesterSummary = semesterSummaryService.queryByPK(id);
          // 获得学生信息
          student.setXsid(semesterSummary.getStuid());
          student = commonService.queryByStudent(student);
          model.put("student", student);
          String p1 = null, p2 = null, p3 = null, p21 = null, p22 = null;
          if (!StringUtils.isNullValue(semesterSummary.getSqxm())) {
            String[] SqxmArr = semesterSummary.getSqxm().split(",");
            for (String i : SqxmArr) {
              switch (i) {
                case Constant.PXXM_TYPE1:
                  p1 = i;
                  break;
                case Constant.PXXM_TYPE2:
                  p2 = i;
                  break;
                case Constant.PXXM_TYPE3:
                  p3 = i;
                  break;
                case Constant.PXXM_TYPE4:
                  p21 = i;

                  break;
                case Constant.PXXM_TYPE5:
                  p22 = i;
                  break;
                default:
                  break;
              }
            }
            model.put("p1", p1);
            model.put("p2", p2);
            model.put("p3", p3);
            model.put("p21", p21);
            model.put("p22", p22);
            model.put("semesterSummary", semesterSummary);
            model.put("msg", BaseController.getParameter("msg"));
            BaseController.removeParameter("msg");
            return "semesterSummary/editManagerSemesterSummary";
          }
        }
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:semesterSummaryManagerIndex?bzr=" + ismanager;
      }
    } catch (Exception e) {
      LOGGER.error("修改学生期末总结信息 modiftySemesterSummaryManagerForward [{}] error,"
          + this.getClass().getName() + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return "redirect:semesterSummaryManagerIndex?bzr=" + ismanager;
  }


  /**
   * 
   * 学生期末总结(管理端) 修改
   * 
   * @param model
   * @param request
   * @param SemesterSummary
   * @return
   */
  @RequestMapping(value = "/modiftyManagerSemesterSummary")
  @SysLogger(description = "学生修改学生期末总结信息", moduleName = "学生期末总结信息", method = "修改")
  public String modiftyManagerSemesterSummary(ModelMap model, HttpServletRequest request,
      SemesterSummary SemesterSummary) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    String ismanager = request.getParameter("ismanager");
    try {
      if (loginType == 2) { // 老师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        String p = request.getParameter("p");
        String p21 = request.getParameter("p21");
        String p22 = request.getParameter("p22");
        String sqxm = "";
        if (!StringUtils.isNullValue(p)) {
          sqxm = sqxm + p + ",";
        }
        if (!StringUtils.isNullValue(p21)) {
          sqxm = sqxm + p21 + ",";
        }
        if (!StringUtils.isNullValue(p22)) {
          sqxm = sqxm + p22 + ",";
        }
        if (!StringUtils.isNullValue(sqxm)) {
          sqxm = sqxm.trim().substring(0, sqxm.trim().length() - 1);
        }
        // SemesterSummary.setBjid(student.getBjid());
        SemesterSummary.setSqxm(sqxm);
        int num = semesterSummaryService.modiftySemesterSummary(SemesterSummary);
        if (num >= 1) {
          BaseController.setParameter("msg", "保存成功");
        } else {
          BaseController.setParameter("msg", "保存失败");
        }
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:semesterSummaryManagerIndex?bzr=" + ismanager;
      }
      model.put("ismanager", ismanager);
    } catch (Exception e) {
      LOGGER.error("修改学生期末总结信息 modiftyManagerSemesterSummary [{}] error,"
          + this.getClass().getName() + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return "redirect:modiftySemesterSummaryManagerForward?zjid=" + SemesterSummary.getZjid()
        + "&ismanager=" + ismanager;

  }

  /**
   * 学生删除末总结信息(学生端)
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/removeManagerSemesterSummary", method = RequestMethod.POST)
  @SysLogger(description = "学生删除学生期末总结信息", moduleName = "学生期末总结信息", method = "删除")
  public String removeManagerSemesterSummary(ModelMap model, HttpServletRequest request) {
    String ismanager = request.getParameter("ismanager");
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      if (loginType == 2) { // 老师
        String[] idList = request.getParameter("idList").split(",");
        if (idList.length >= 1) {
          int num = semesterSummaryService.deleteSemesterSummary(idList);
          if (num >= 1) {
            BaseController.setParameter("msg", "删除成功");
          } else {
            BaseController.setParameter("msg", "删除失败");
          }
        }
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
      }
      return "redirect:semesterSummaryManagerIndex?bzr=" + ismanager;
    } catch (Exception e) {
      LOGGER.error("删除学生期末总结信息 removeManagerSemesterSummary [{}] error," + this.getClass().getName()
          + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
  }

  /**
   * 学生期末总结信息导出(管理端)
   * 
   * @param form
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  @RequestMapping(value = "/exportManagerSemesterSummary")
  public @ResponseBody String exportManagerSemesterSummary(HttpServletRequest request,
      HttpServletResponse response, /* @RequestParam("bodyData") String bodyData, */ ModelMap model,
      SemesterSummary semesterSummary) throws Exception {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      String[][] title_name = {{"姓名", "学号", "学期", "本学期取得的荣誉", "本学期申请的先进项目"}};
      String[] title_style = {"hwzs_16_bold_25", "kt_12_bold_18", "st_12_r_20", "st_12_n_20"};
      String fileName = "学生期末总结信息";
      String[] remark = {""};
      List<Map<String, Object>> exportlist = new ArrayList<Map<String, Object>>();
      if (loginType == 2) { // 老师
        // List<SemesterSummary> list = JSONArray.parseArray(bodyData, SemesterSummary.class);
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        String ismanager = request.getParameter("ismanager");
        semesterSummary.setIsmanager(Integer.parseInt(ismanager));
        semesterSummary.setBzrid(userEmployee.getEmid());
        Page page = BaseController.getPage("0", "0", request, "xh", "asc");
        semesterSummary.setOrderField((String) request.getAttribute("orderField"));
        semesterSummary.setOrderFlag((String) request.getAttribute("orderFlag"));
        // if (semesterSummary.getNjid() == null) {
        // semesterSummary.setNjid((Integer) request.getSession().getAttribute("gradeid"));
        // }
        List<SemesterSummary> list =
            semesterSummaryService.exportSemesterSummaryList(semesterSummary);
        if (!list.isEmpty()) {
          for (SemesterSummary res : list) {
            Map<String, Object> map = new LinkedHashMap<String, Object>();
            map.put("name", res.getXm());
            map.put("xh", res.getXh());
            map.put("xq", res.getXqmc());
            map.put("hdry", res.getHdry());
            map.put("sqxm", res.getSqxm());
            exportlist.add(map);
          }
        }
      }
      HSSFWorkbook wb =
          ExpExcelUtil.getWorkBookExcel(title_name, title_style, 100, remark, fileName, exportlist);
      // String filenameConvert = "xxxxx信息";/* new String(fileName.getBytes("GB2312"), "ISO8859-1");
      // */
      response.reset();
      response.setContentType("application/vnd.ms-excel;charset=utf-8");
      response.setHeader("Content-Disposition",
          "attachment;filename=" + new String((fileName + ".xls").getBytes(), "iso-8859-1"));
      response.setDateHeader("Expires", 0);
      ServletOutputStream os = response.getOutputStream();
      wb.write(os);
      os.flush();
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("导出学生期末总结信息 exportManagerSemesterSummary [{}] error," + this.getClass().getName()
          + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return null;
  }

  /**
   * 学生推荐列表页面跳转页面(管理端)
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/recommendStudentIndex")
  public String recommendStudentIndex(ModelMap model, HttpServletRequest request) {
    try {
      request.setAttribute("msg", BaseController.getParameter("msg"));
      BaseController.removeParameter("msg");
      // 获得标准信息
      BaseController.getSemesterList(model, commonService);
      BaseController.getSemester(model, commonService);
      // 获得年级信息
      BaseController.getGradeList(model, commonService);
      // 获得专业
      BaseController.getSpecialityList(model, commonService);
      Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
      BaseController.getClassListAndBzrid(request, model, commonService, loginType);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "学生期末总结列表 recommendStudentIndex [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return "semesterSummary/recommendStudent_list";
  }

  /**
   * 学生推荐列表(管理端)
   * 
   * @param model
   * @param request
   * @param pageSize
   * @param currentPage
   * @param data
   * @return
   */
  @RequestMapping(value = "/recommendStudentList")
  @ResponseBody
  public ResponseResult recommendStudentList(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "rows", required = false) String pageSize,
      @RequestParam(value = "page", required = false) String currentPage, RecommendStudent data) {
    ResponseResult result = new ResponseResult();
    try {
      Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
      switch (loginType) {
        case 1: // 学生端
          Student student =
              (Student) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
          data.setCreatorid(student.getXsid());
          break;
        case 2: // 老师端
          UserEmployee userEmployee =
              (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
          String bzr = request.getParameter("bzr");
          if (bzr.equals(Constant.IS_BZR)) {
            data.setCreatorid(userEmployee.getEmid());
          }
        default:
          break;
      }
      Page page = BaseController.getPage(currentPage, pageSize, request, "xh", "asc");
      data.setOrderField((String) request.getAttribute("orderField"));
      data.setOrderFlag((String) request.getAttribute("orderFlag"));
      PaginationBean<RecommendStudent> paginationBean =
          recommendStudentService.queryRecommendStudentPageList(data, page);
      if (paginationBean.getPageList().isEmpty()) {
        result.setRows(new ArrayList<RecommendStudent>());
      } else {
        result.setRows(paginationBean.getPageList());
      }
      result.setTotal(paginationBean.getTotalRecords());
      return result;
    } catch (Exception e) {
      result.setRows(new ArrayList<RecommendStudent>());
      result.setTotal(0);
      e.printStackTrace();
      LOGGER.error("获得学生期末总结列表信息(管理端) semesterSummaryManagerList [{}] error,"
          + this.getClass().getName() + "=[{}]", this.getClass().getName(), e.getMessage());
    }
    return result;
  }

  /**
   * 期末评比推荐表新增页面跳转
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/addRecommendStudentForward")
  @Token(save = true)
  public String addRecommendStudentForward(ModelMap model, HttpServletRequest request) {
    try {
      Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
      String bzr = request.getParameter("ismanager");
      // 获得标准信息
      BaseController.getSemesterList(model, commonService);
      BaseController.getSemester(model, commonService);
      model.put("currentDate", DateUtil.formatDate2Str(new Date(), "yyyy-MM-dd hh:mm:ss"));
      model.put("msg", BaseController.getParameter("msg"));
      BaseController.removeParameter("msg");
      model.put(BaseController.TEACHER_IS_MANAGER, bzr);
    } catch (Exception e) {
      LOGGER.error("获得期末评比推荐表信息 addRecommendStudentForward [{}] error," + this.getClass().getName()
          + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return "semesterSummary/addRecommendStudent";

  }

  /**
   * 期末评比推荐表保存功能
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/addRecommendStudent")
  @Token(remove = true, path = "recommendStudentIndex")
  @SysLogger(description = "新增期末评比推荐表信息", moduleName = "期末评比推荐表", method = "新增")
  public String addRecommendStudent(ModelMap model, HttpServletRequest request,
      RecommendStudent recommendStudent) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      switch (loginType) {
        case 1: // 学生端
          Student student =
              (Student) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
          recommendStudent.setCreatorid(student.getXsid());
          recommendStudent.setCreatorname(student.getXm());
          break;
        case 2: // 老师端
          UserEmployee userEmployee =
              (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
          recommendStudent.setCreatorid(
              userEmployee.getEmid() == null ? userEmployee.getUid() : userEmployee.getEmid());
          recommendStudent.setCreatorname(
              userEmployee.getXm() == null ? userEmployee.getName() : userEmployee.getXm());
        default:
          break;
      }
      recommendStudent.setGid(UUIDGenerator.genReqID());
      recommendStudent.setCreatetime(new Date());
      String p1 = request.getParameter("p");
      String p21 = request.getParameter("p21");
      String p22 = request.getParameter("p22");
      String sqxm = "";
      if (!StringUtils.isNullValue(p1)) {
        recommendStudent.setPxxm1(p1);
      }
      if (!StringUtils.isNullValue(p21)) {
        sqxm = sqxm + p21 + ",";
      }
      if (!StringUtils.isNullValue(p22)) {
        sqxm = sqxm + p22 + ",";
      }
      if (!StringUtils.isNullValue(sqxm)) {
        sqxm = sqxm.trim().substring(0, sqxm.trim().length() - 1);
      }
      // recommendStudent.setBjid(student.getBjid());
      recommendStudent.setPxxm2(sqxm);
      recommendStudent.setCreatetime(
          DateUtil.parseStr2Date(request.getParameter("desj"), "yyyy-MM-dd hh:mm:ss"));
      int tjid = recommendStudentService.addRecommendStudent(recommendStudent);
      String flag = request.getParameter("flag");
      if (tjid >= 1 && !StringUtils.isNullValue(flag) && "1".equals(flag)) { // 新增跳转到修改页面
        // 根据guid获得zjid信息
        // recommendStudent =
        // recommendStudentService.queryGidRecommendStudent(recommendStudent.getGid());
        BaseController.setParameter("msg", "保存成功");
        return "redirect:modiftyRecommendStudentForward?tjid=" + tjid + "&ismanager="
            + request.getParameter("ismanager");
      } else if (tjid >= 1 && !StringUtils.isNullValue(flag) && "2".equals(flag)) { // 新增且继续新增
        BaseController.setParameter("msg", "保存成功");
        return "redirect:addRecommendStudentForward?ismanager=" + request.getParameter("ismanager");
      } else {
        BaseController.setParameter("msg", "保存失败");
        return "redirect:recommendStudentIndex?bzr=" + request.getParameter("ismanager");
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "新增学生推荐表信息 addRecommendStudent [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
  }

  /**
   * 
   * 学生推荐表信息修改跳转页面
   * 
   * @param model
   * @param request
   * @param id
   * @return
   */
  @RequestMapping(value = "/modiftyRecommendStudentForward", method = RequestMethod.GET)
  public String modiftyRecommendStudentForward(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "tjid") Integer id) {
    try {
      String ismanager = request.getParameter("ismanager");
      // 获取标准信息
      BaseController.getSemesterList(model, commonService);
      // BaseController.getSemester(model, commonService);
      // 获得学生学期各科成绩
      List<Student> studentCourseScoreList = null;
      Student student = new Student();
      if (id != null) {
        RecommendStudent recommendStudent = recommendStudentService.queryRecommendStudent(id);
        // 获得学生信息
        student.setXsid(recommendStudent.getStuid());
        student.setYxid(recommendStudent.getSemid());
        studentCourseScoreList = commonService.querySemesterStudentScoreConductList(student);
        String p21 = null, p22 = null;
        if (!StringUtils.isNullValue(recommendStudent.getPxxm2())) {
          String[] pxxmArr = recommendStudent.getPxxm2().split(",");
          for (String i : pxxmArr) {
            switch (i) {
              case "优秀班干部":
                p21 = i;
                break;
              case "技能特长生":
                p22 = i;
                break;
              default:
                break;
            }
          }
        }
        // 获得学生基本信息
        student = commonService.queryByStudent(student);
        model.put("studentCourseScoreList", studentCourseScoreList);
        model.put("p21", p21);
        model.put("p22", p22);
        model.put("recommendStudent", recommendStudent);
        model.put("student", student);
        // 获得满足条件初始化学生信息
        Integer type = getStudentPbType(recommendStudent);
        List<Student> studentList = new ArrayList<Student>();
        if (type != null) {
          Student stu = new Student();
          stu.setPytype(type);
          stu.setYxid(recommendStudent.getSemid());
          switch (type) {
            case 1: // 行为达标生
              stu.setCxgrades(new String[] {"合格"});
              break;
            case 2: // 好学生
              stu.setCxgrades(new String[] {"良", "优"});
              break;
            case 3: // 三好学生
              stu.setCxgrades(new String[] {"优"});
              break;
            case 4: // 优秀班干部
              stu.setCxgrades(new String[] {"优"});
              break;
            case 5: // 技能特长生
              stu.setCxgrades(null);
              break;
            case 6: // 优秀班干部和技能特长生
              stu.setCxgrades(new String[] {"优"});
              break;
            default:
              stu.setCxgrades(null);
              break;
          }
          if (ismanager.equals(Constant.IS_BZR)) { // 判断是否是班主任
            UserEmployee userEmployee =
                (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
            stu.setBzrid(userEmployee.getEmid());
          }
          studentList = commonService.querySemesterByStudentConductList(stu);
        }
        model.put("studentList", studentList);
        model.put("msg", BaseController.getParameter("msg"));
        BaseController.removeParameter("msg");
        model.put(BaseController.TEACHER_IS_MANAGER, ismanager);
        return "semesterSummary/editRecommendStudent";
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("修改学生推荐表信息 modiftyRecommendStudentForward [{}] error,"
          + this.getClass().getName() + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return "redirect:recommendStudentIndex?bzr=" + request.getParameter("ismanager");

  }

  /**
   * 获得评比项
   * 
   * @param recommendStudent
   * @return
   */
  private static Integer getStudentPbType(RecommendStudent recommendStudent) {
    Integer type = null;
    Integer type1 = null;
    Integer type2 = null;
    if (recommendStudent != null) {
      if (StringUtils.isNullValue(recommendStudent.getPxxm1())
          && Constant.PXXM_TYPE1.equals(recommendStudent.getPxxm1())) {
        type1 = 3;
      } else if (StringUtils.isNullValue(recommendStudent.getPxxm1())
          && Constant.PXXM_TYPE2.equals(recommendStudent.getPxxm1())) {
        type1 = 2;
      } else if (StringUtils.isNullValue(recommendStudent.getPxxm1())
          && Constant.PXXM_TYPE3.equals(recommendStudent.getPxxm1())) {
        type1 = 1;
      }
      if (!StringUtils.isNullValue(recommendStudent.getPxxm2())) {
        String[] pxxmArr = recommendStudent.getPxxm2().split(",");
        if (pxxmArr.length == 1 && Constant.PXXM_TYPE4.equals(pxxmArr[0])) {
          type2 = 4;
        } else if (pxxmArr.length == 1 && Constant.PXXM_TYPE5.equals(pxxmArr[0])) {
          type2 = 5;
        } else {
          type2 = 6;
        }
      }
      if (type1 != null && type2 == null) {
        type = type1;
      } else if (type1 != null && type2 != null) {
        type = type2;
      } else if (type1 == null && type2 != null) {
        type = type2;
      }
    }
    return type;
  }


  /**
   * 
   * 学生推荐表信息修改
   * 
   * @param model
   * @param request
   * @param SemesterSummary
   * @return
   */
  @RequestMapping(value = "/modiftyRecommendStudent")
  @SysLogger(description = "学生修改学生推荐表信息", moduleName = "学生推荐表信息", method = "修改")
  public String modiftyRecommendStudent(ModelMap model, HttpServletRequest request,
      RecommendStudent recommendStudent) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      switch (loginType) {
        case 1: // 学生端
          Student student =
              (Student) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
          recommendStudent.setCreatorid(student.getXsid());
          recommendStudent.setCreatorname(student.getXm());
          break;
        case 2: // 老师端
          UserEmployee userEmployee =
              (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
          recommendStudent.setCreatorid(userEmployee.getEmid());
          recommendStudent.setCreatorname(userEmployee.getXm());
        default:
          break;
      }
      String p = request.getParameter("p");
      String p21 = request.getParameter("p21");
      String p22 = request.getParameter("p22");
      String sqxm = "";
      recommendStudent.setPxxm1(p);
      if (!StringUtils.isNullValue(p21)) {
        sqxm = sqxm + p21 + ",";
      }
      if (!StringUtils.isNullValue(p22)) {
        sqxm = sqxm + p22 + ",";
      }
      if (!StringUtils.isNullValue(sqxm)) {
        sqxm = sqxm.trim().substring(0, sqxm.trim().length() - 1);
      }
      recommendStudent.setCreatetime(
          DateUtil.parseStr2Date(request.getParameter("desj"), "yyyy-MM-dd hh:mm:ss"));
      // SemesterSummary.setBjid(student.getBjid());
      recommendStudent.setPxxm2(sqxm);
      int num = recommendStudentService.modiftyRecommendStudent(recommendStudent);
      if (num >= 1) {
        BaseController.setParameter("msg", "保存成功");
      } else {
        BaseController.setParameter("msg", "保存失败");
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "修改学生推荐表信息 modiftyRecommendStudent [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return "redirect:modiftyRecommendStudentForward?tjid=" + recommendStudent.getTjid()
        + "&ismanager=" + request.getParameter("ismanager");

  }

  /**
   * 删除学生推荐表信息
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/removeRecommendStudent", method = RequestMethod.POST)
  @SysLogger(description = "删除学生推荐表信息", moduleName = "学生推荐表信息", method = "删除")
  public String removeRecommendStudent(ModelMap model, HttpServletRequest request) {
    try {
      String[] idList = request.getParameter("idList").split(",");
      if (idList.length >= 1) {
        int num = recommendStudentService.removeRecommendStudent(idList);
        if (num >= 1) {
          BaseController.setParameter("msg", "删除成功");
        } else {
          BaseController.setParameter("msg", "删除失败");
        }
      }
      return "redirect:recommendStudentIndex?bzr=" + request.getParameter("ismanager");
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "删除学生推荐表信息 removeRecommendStudent [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
  }

  /**
   * 学生推荐表信息导出
   * 
   * @param form
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  @RequestMapping(value = "/exportRecommendStudent")
  public @ResponseBody String exportRecommendStudent(HttpServletRequest request,
      HttpServletResponse response, /* @RequestParam("bodyData") String bodyData, */ ModelMap model,
      RecommendStudent recommendStudent) throws Exception {
    // Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      String[][] title_name = {{"姓名", "学号", "班级", "学期", "评选项目", "推荐人"}};
      String[] title_style = {"hwzs_16_bold_25", "kt_12_bold_18", "st_12_r_20", "st_12_n_20"};
      String fileName = "学生推荐表信息";
      String[] remark = {""};
      List<Map<String, Object>> exportlist = new ArrayList<Map<String, Object>>();
      // List<RecommendStudent> list = JSONArray.parseArray(bodyData, RecommendStudent.class);
      Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
      switch (loginType) {
        case 1: // 学生端
          Student student =
              (Student) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
          recommendStudent.setCreatorid(student.getXsid());
          break;
        case 2: // 老师端
          UserEmployee userEmployee =
              (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
          String ismanager = request.getParameter("ismanager");
          if (ismanager.equals(Constant.IS_BZR)) {
            recommendStudent.setCreatorid(userEmployee.getEmid());
          }
        default:
          break;
      }
      Page page = BaseController.getPage("0", "0", request, "xh", "asc");
      recommendStudent.setOrderField((String) request.getAttribute("orderField"));
      recommendStudent.setOrderFlag((String) request.getAttribute("orderFlag"));
      List<RecommendStudent> list =
          recommendStudentService.exportRecommendStudentList(recommendStudent);
      if (!list.isEmpty()) {
        for (RecommendStudent res : list) {
          Map<String, Object> map = new LinkedHashMap<String, Object>();
          map.put("name", res.getXm());
          map.put("xh", res.getXh());
          map.put("bjmc", res.getBjmc());
          map.put("xqmc", res.getXqmc());
          map.put("pxxm", res.getPxxm1());
          map.put("tjr", res.getCreatorname());
          exportlist.add(map);
        }
      }
      HSSFWorkbook wb =
          ExpExcelUtil.getWorkBookExcel(title_name, title_style, 100, remark, fileName, exportlist);
      // String filenameConvert = "xxxxx信息";/* new String(fileName.getBytes("GB2312"), "ISO8859-1");
      // */
      response.reset();
      response.setContentType("application/vnd.ms-excel;charset=utf-8");
      response.setHeader("Content-Disposition",
          "attachment;filename=" + new String((fileName + ".xls").getBytes(), "iso-8859-1"));
      response.setDateHeader("Expires", 0);
      ServletOutputStream os = response.getOutputStream();
      wb.write(os);
      os.flush();
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "导出学生推荐表信息 exportRecommendStudent [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return null;
  }

  /**
   * 班级汇总
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/recommendStudentClassReport")
  public String recommendStudentClassReport(ModelMap model, HttpServletRequest request) {
    try {
      Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
      if (loginType == 2) { // 老师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        BaseController.getClassListAndBzrid(request, model, commonService, loginType);
        // 获得标准信息
        // BaseController.getSemesterList(model, commonService);
        List<Semester> semesterList = recommendStudentService.queryRecommendStudentAllTerm();
        // 获得统计数据
        String njid = request.getParameter("njid");
        String zyid = request.getParameter("zyid");
        String bjid = request.getParameter("bjid");
        String semid = request.getParameter("semid");
        if (!semesterList.isEmpty()) {
          model.put("semesterList", semesterList);
          // 获得年级信息
          model.put("njid", njid);
          BaseController.getGradeList(model, commonService);
          // 获得专业
          model.put("zyid", zyid);
          BaseController.getSpecialityList(model, commonService);
          model.put("bjid", bjid);
          model.put("semid", semid);
          Student student = new Student();
          if (StringUtils.isNullValue(semid)) {
            BaseController.getSemester(model, commonService);
            Semester semester = (Semester) model.get("semester");
            student.setYxid(semester.getXqid());
          } else {
            student.setYxid(Integer.parseInt(semid));
          }
          if (!StringUtils.isNullValue(njid)) {
            student.setNjid(Integer.parseInt(njid));
          }
          if (!StringUtils.isNullValue(zyid)) {
            student.setZyid(Integer.parseInt(zyid));
          }
          if (!StringUtils.isNullValue(bjid)) {
            student.setBjid(Integer.parseInt(bjid));
          }
          if (model.get(BaseController.TEACHER_IS_MANAGER) != null
              && ((String) model.get(BaseController.TEACHER_IS_MANAGER)).equals(Constant.IS_BZR)) {
            student.setBzrid(userEmployee.getEmid());
          }
          List<RecommendStudent> recommendStudentList =
              recommendStudentService.queryRecommendStudentClassReport(student);
          List<StudentClass> bjList = new ArrayList<StudentClass>();
          List<Integer> bjIds = new ArrayList<Integer>();
          StudentClass studentClass = null;
          if (!recommendStudentList.isEmpty()) {
            // 获取班级信息
            for (RecommendStudent r : recommendStudentList) {
              if (!bjIds.contains(r.getBjid())) {
                studentClass = new StudentClass();
                studentClass.setBjid(r.getBjid());
                studentClass.setBjmc(r.getBjmc());
                bjList.add(studentClass);
                bjIds.add(r.getBjid());
              }
            }
            Semester s = new Semester();
            s.setXqid(student.getYxid());
            Semester semester = commonService.queryBySemester(s);
            // 生成报表数据
            String dataTableHtml =
                buidRecommendStudentSchoolReport(bjList, recommendStudentList, semester);
            model.put("dataTableHtml", dataTableHtml);
          } else {
            model.put("msg", "统计的信息未生成报表信息,无法完成数据汇总");
          }
          model.put("bzrname", userEmployee.getXm());
          // model.put("bjmc",userEmployee.)
        } else {
          model.put("msg", "统计的信息未生成报表信息,无法完成数据汇总");
        }

      } else {
        model.put("msg", "您没权限访问该页面");
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "学生期末总结列表 recommendStudentIndex [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return "semesterSummary/recommendStudentCLass_Report";
  }

  /**
   * 生成页面信息
   * 
   * @param recommendStudentList
   * @return
   */
  private static String buidRecommendStudentSchoolReport(List<StudentClass> bjList,
      List<RecommendStudent> recommendStudentList, Semester semester) {
    StringBuilder sb0 = null; // 技能特长生
    StringBuilder sb1 = null; // 好学生
    StringBuilder sb2 = null; // 三好学生
    StringBuilder sb3 = null; // 行为达标生
    StringBuilder sb4 = null; // 优秀班干部
    StringBuilder sb5 = null; // 技能特长生
    StringBuffer sb = new StringBuffer(500);
    int num = 0;
    boolean bool = false;
    for (StudentClass studentClass : bjList) { // 所有班级信息
      num++;
      sb0 = new StringBuilder(500);
      sb1 = new StringBuilder(200);
      sb2 = new StringBuilder(200);
      sb3 = new StringBuilder(200);
      sb4 = new StringBuilder(200);
      sb5 = new StringBuilder(200);
      bool = false;
      sb0.append("<table id=tab_'" + num
          + "' cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"table-border\" width=\"80%\">");
      sb0.append(
          "<tr><td colspan=\"6\" class=\"table-contentTD2\" style=\"width: 1%;text-align:center;border: 0\"><h3>"
              + semester.getXqmc() + "<br/>三好学生、优秀班干部、好学生、行为达标生、技能特长生名单汇总</h3></td>");
      sb0.append(
          "<tr><td colspan=\"3\" class=\"table-contentTD2\" style=\"width: 1%;border: 0;\"><h5>班级:"
              + studentClass.getBjmc() + "</h5></td>");
      sb0.append(
          "<td colspan=\"3\" class=\"table-contentTD2\" style=\"width: 1%;border: 0;\"><h3>班主任签名:</h3></td></tr>");
      List<RecommendStudent> classList =
          getClassRecommendStudentList(studentClass.getBjid(), recommendStudentList);
      for (RecommendStudent r : classList) {
        switch (r.getPxxm()) {
          case Constant.PXXM_TYPE2:
            if (StringUtils.isNullValue(r.getXm())) {
              sb1.append("<tr><td class=\"table-contentTD2\" style=\"width: 1%\" rowspan=\"2\">"
                  + r.getPxxm() + "<br/>" + r.getCout() + "人</td>");
              sb1.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb1.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb1.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb1.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb1.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb1.append("</tr><tr>");
              sb1.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb1.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb1.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb1.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb1.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb1.append("</tr>");
              bool = true;
            } else {
              String[] students = new String[10];
              String[] xms = r.getXm().split(",");
              int len = xms.length;
              if (len >= 11) {
                len = 10;
              }
              for (int i = 0; i < len; i++) {
                students[i] = xms[i];
              }
              int len2 = students.length;
              if (len2 > len) {
                for (int j = len; j < len2; j++) {
                  students[j] = " ";
                }
              }
              int cout = 1;
              for (String stu : students) {
                if (cout == 1) {
                  sb2.append("<tr><td class=\"table-contentTD2\" style=\"width:1%\" rowspan=\"2\">"
                      + r.getPxxm() + "<br/>" + r.getCout() + "人</td>");
                  sb2.append("<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                } else {
                  if (cout <= 4) {
                    sb2.append(
                        "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                  } else if (cout == 5) {
                    sb2.append(
                        "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                    sb2.append("</tr>");
                  } else {
                    if (cout == 6) {
                      sb2.append("<tr>");
                      sb2.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                    } else if (cout >= 7 && cout <= 9) {
                      sb2.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                    } else {
                      sb2.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                      sb2.append("</tr>");
                    }
                  }
                }
                bool = true;
                cout++;
              }
            }
            break;
          case Constant.PXXM_TYPE1:
            if (StringUtils.isNullValue(r.getXm())) {
              sb2.append("<tr><td class=\"table-contentTD\" style=\"width:1%\" rowspan=\"2\">"
                  + r.getPxxm() + "<br/>" + r.getCout() + "人</td>");
              sb2.append("<td class=\"table-contentTD2\" style=\"width:1%\"></td>");
              sb2.append("<td class=\"table-contentTD2\" style=\"width:1%\"></td>");
              sb2.append("<td class=\"table-contentTD2\" style=\"width:1%\"></td>");
              sb2.append("<td class=\"table-contentTD2\" style=\"width:1%\"></td>");
              sb2.append("<td class=\"table-contentTD2\" style=\"width:1%\"></td>");
              sb2.append("</tr><tr>");
              sb2.append("<td class=\"table-contentTD2\" style=\"width:1%\"></td>");
              sb2.append("<td class=\"table-contentTD2\" style=\"width:1%\"></td>");
              sb2.append("<td class=\"table-contentTD2\" style=\"width:1%\"></td>");
              sb2.append("<td class=\"table-contentTD2\" style=\"width:1%\"></td>");
              sb2.append("<td class=\"table-contentTD2\" style=\"width:1%\"></td>");
              sb2.append("</tr>");
              bool = true;
            } else {
              String[] students = new String[10];
              String[] xms = r.getXm().split(",");
              int len = xms.length;
              if (len >= 11) {
                len = 10;
              }
              for (int i = 0; i < len; i++) {
                students[i] = xms[i];
              }
              int len2 = students.length;
              if (len2 > len) {
                for (int j = len; j < len2; j++) {
                  students[j] = " ";
                }
              }
              int cout = 1;
              for (String stu : students) {
                if (cout == 1) {
                  sb2.append("<tr><td class=\"table-contentTD2\" style=\"width:1%\" rowspan=\"2\">"
                      + r.getPxxm() + "<br/>" + r.getCout() + "人</td>");
                  sb2.append("<td class=\"table-contentTD2\" style=\"width:1%\">" + stu + "</td>");
                } else {
                  if (cout <= 4) {
                    sb2.append(
                        "<td class=\"table-contentTD2\" style=\"width:1%\">" + stu + "</td>");
                  } else if (cout == 5) {
                    sb2.append(
                        "<td class=\"table-contentTD2\" style=\"width:1%\">" + stu + "</td>");
                    sb2.append("</tr>");
                  } else {
                    if (cout == 6) {
                      sb2.append("<tr>");
                      sb2.append(
                          "<td class=\"table-contentTD2\" style=\"width:1%\">" + stu + "</td>");
                    } else if (cout >= 7 && cout <= 9) {
                      sb2.append(
                          "<td class=\"table-contentTD2\" style=\"width:1%\">" + stu + "</td>");
                    } else {
                      sb2.append(
                          "<td class=\"table-contentTD2\" style=\"width:1%\">" + stu + "</td>");
                      sb2.append("</tr>");
                    }
                  }
                }
                bool = true;
                cout++;
              }
            }
            break;
          case Constant.PXXM_TYPE3:
            if (StringUtils.isNullValue(r.getXm())) {
              sb3.append("<tr><td class=\"table-contentTD2\" style=\"width:1%\" rowspan=\"8\">"
                  + r.getPxxm() + "<br/>" + r.getCout() + "人</td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("</tr><tr>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("</tr>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("</tr>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("</tr>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("</tr>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("</tr>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("</tr>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb3.append("</tr>");
              bool = true;
            } else {
              String[] students = new String[40];
              String[] xms = r.getXm().split(",");
              int len = xms.length;
              if (len >= 41) {
                len = 40;
              }
              for (int i = 0; i < len; i++) {
                students[i] = xms[i];
              }
              int len2 = students.length;
              if (len2 > len) {
                for (int j = len; j < len2; j++) {
                  students[j] = " ";
                }
              }
              int cout = 1;
              for (String stu : students) {
                if (cout == 1) {
                  sb3.append("<tr><td class=\"table-contentTD2\" style=\"width: 1%\" rowspan=\"8\">"
                      + r.getPxxm() + "<br/>" + r.getCout() + "人</td>");
                  sb3.append("<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                } else {
                  if (cout <= 4) {
                    sb3.append(
                        "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                  } else if (cout == 5) {
                    sb3.append(
                        "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                    sb3.append("</tr>");
                  } else {
                    if (cout == 6) {
                      sb3.append("<tr>");
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                    } else if (cout >= 7 && cout <= 9) {
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                    } else if (cout == 10) {
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                      sb3.append("</tr>");
                    } else if (cout == 11) {
                      sb3.append("<tr>");
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                    } else if (cout >= 12 && cout <= 14) {
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                    } else if (cout == 15) {
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                      sb3.append("</tr>");
                    } else if (cout == 16) {
                      sb3.append("<tr>");
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                    } else if (cout >= 17 && cout <= 19) {
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                    } else if (cout == 20) {
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                      sb3.append("</tr>");
                    } else if (cout == 21) {
                      sb3.append("<tr>");
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                    } else if (cout >= 22 && cout <= 24) {
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                    } else if (cout == 25) {
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                      sb3.append("</tr>");
                    } else if (cout == 26) {
                      sb3.append("<tr>");
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                    } else if (cout >= 27 && cout <= 29) {
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                    } else if (cout == 30) {
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                      sb3.append("</tr>");
                    } else if (cout == 31) {
                      sb3.append("<tr>");
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                    } else if (cout >= 32 && cout <= 34) {
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                    } else if (cout == 35) {
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                      sb3.append("</tr>");
                    } else if (cout == 36) {
                      sb3.append("<tr>");
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                    } else if (cout >= 37 && cout <= 39) {
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                    } else if (cout == 40) {
                      sb3.append(
                          "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                      sb3.append("</tr>");
                    }
                  }
                }
                bool = true;
                cout++;
              }
            }
            break;
          case Constant.PXXM_TYPE4:
            if (StringUtils.isNullValue(r.getXm())) {
              sb4.append("<tr><td class=\"table-contentTD2\" style=\"width: 1%\" rowspan=\"1\">"
                  + r.getPxxm() + "<br/>'" + r.getCout() + "'人</td>");
              sb4.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb4.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb4.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb4.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb4.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb4.append("</tr>");
              bool = true;
            } else {
              String[] students = new String[5];
              String[] xms = r.getXm().split(",");
              int len = xms.length;
              if (len >= 6) {
                len = 5;
              }
              for (int i = 0; i < len; i++) {
                students[i] = xms[i];
              }
              int len2 = students.length;
              if (len2 > len) {
                for (int j = len; j < len2; j++) {
                  students[j] = " ";
                }
              }
              int cout = 1;
              for (String stu : students) {
                if (cout == 1) {
                  sb4.append("<tr><td class=\"table-contentTD2\" style=\"width: 1%\" rowspan=\"1\">"
                      + r.getPxxm() + "<br/>" + r.getCout() + "人</td>");
                  sb4.append("<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                } else {
                  if (cout <= 4) {
                    sb4.append(
                        "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                  } else if (cout == 5) {
                    sb4.append(
                        "<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                    sb4.append("</tr>");
                  }
                }
                bool = true;
                cout++;
              }
            }
            break;
          case Constant.PXXM_TYPE5:
            if (StringUtils.isNullValue(r.getXm())) {
              sb5.append("<tr><td class=\"table-contentTD\" style=\"width:1%\" rowspan=\"1\">"
                  + r.getPxxm() + "<br/>" + r.getCout() + "人</td>");
              sb5.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb5.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb5.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb5.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb5.append("<td class=\"table-contentTD2\" style=\"width: 1%\"></td>");
              sb5.append("</tr>");
              bool = true;
            } else {
              String[] students = new String[5];
              String[] xms = r.getXm().split(",");
              int len = xms.length;
              if (len >= 6) {
                len = 5;
              }
              for (int i = 0; i < len; i++) {
                students[i] = xms[i];
              }
              int len2 = students.length;
              if (len2 > len) {
                for (int j = len; j < len2; j++) {
                  students[j] = " ";
                }
              }
              int cout = 1;
              for (String stu : students) {
                if (cout == 1) {
                  sb5.append("<tr><td class=\"table-contentTD2\" style=\"width:1%\" rowspan=\"1\">"
                      + r.getPxxm() + "<br/>" + r.getCout() + "人</td>");
                  sb5.append("<td class=\"table-contentTD2\" style=\"width: 1%\">" + stu + "</td>");
                } else {
                  if (cout <= 4) {
                    sb5.append(
                        "<td class=\"table-contentTD2\" style=\"width:1%\">" + stu + "</td>");
                  } else if (cout == 5) {
                    sb5.append(
                        "<td class=\"table-contentTD2\" style=\"width:1%\">" + stu + "</td>");
                    sb5.append("</tr>");
                  }
                }
                bool = true;
                cout++;
              }
            }
            break;
          default:
            break;
        }

      }
      if (bool == true) {
        sb0.append(sb2).append(sb4).append(sb1).append(sb3).append(sb5);
        sb0.append(
            "<tr><td class=\"table-contentTD2\"colspan=\"6\">说明：<br/>1.三好学生、行为达标生不能重复，技能特长生原则上限制高二、高三年级；<br/>2.三好学生、优秀班干部、技能特长生需要填写个人推荐评比表</td></tr>");
        sb0.append("</table><br/>");
        sb.append(sb0);
      }

    }
    return sb.toString();

  }

  private static List<RecommendStudent> getClassRecommendStudentList(Integer bjid,
      List<RecommendStudent> recommendStudentList) {
    List<RecommendStudent> list = new ArrayList<RecommendStudent>();
    for (RecommendStudent r : recommendStudentList) {
      if (bjid.intValue() == r.getBjid().intValue()) {
        list.add(r);
      }
    }
    return list;
  }


  /**
   * 学校汇总
   * 
   * @param model
   * @param request
   * @return
   */

  @RequestMapping(value = "/recommendStudentSchoolReport")
  public String recommendStudentSchoolReport(ModelMap model, HttpServletRequest request) {
    try {
      Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
      if (loginType == 2) { // 老师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        BaseController.getClassListAndBzrid(request, model, commonService, loginType);
        // 获得标准信息
        List<Semester> semesterList = recommendStudentService.queryRecommendStudentAllTerm();
        // 获得年级信息
        Grade grade = new Grade();
        Student student = new Student();
        if (model.get(BaseController.STUDENT_BZRID) != null) {
          grade.setBzrid((Integer) model.get(BaseController.STUDENT_BZRID));
          student.setBzrid((Integer) model.get(BaseController.STUDENT_BZRID));
        }
        List<Grade> gradeList = recommendStudentService.queryRecommendStudentAllGrade(grade);
        if (!semesterList.isEmpty()) {
          model.put("semesterList", semesterList);
          // 获得统计数据
          String semid = request.getParameter("semid");

          Semester semester = null;
          if (StringUtils.isNullValue(semid)) {
            BaseController.getSemester(model, commonService);
            semester = (Semester) model.get("semester");
            student.setYxid(semester.getXqid());
            model.put("semid", semester.getXqid());
          } else {
            student.setYxid(Integer.parseInt(semid));
            Semester s = new Semester();
            s.setXqid(Integer.parseInt(semid));
            semester = commonService.queryBySemester(s);
            model.put("semid", semid);
          }
          List<RecommendStudent> recommendStudentList =
              recommendStudentService.queryRecommendStudentSchoolReport(student);
          // 三好学生汇总
          List<RecommendStudentBean> list1 =
              getSchoolRecommendStudentList(gradeList, recommendStudentList, Constant.PXXM_TYPE1);
          // 汇总学期人数
          Integer sum1 = 0;
          RecommendStudentBean xqbean1 = new RecommendStudentBean();
          if (!list1.isEmpty()) {
            for (RecommendStudentBean r1 : list1) {
              sum1 = sum1 + r1.getNjCount();
            }
            xqbean1 = new RecommendStudentBean();
            xqbean1.setXqCount(sum1);
            xqbean1.setXqmc(semester.getXqmc());
            xqbean1.setPxxm(Constant.PXXM_TYPE1);
          } else {
            xqbean1 = new RecommendStudentBean();
            xqbean1.setXqCount(0);
            xqbean1.setXqmc(semester.getXqmc());
            xqbean1.setPxxm(Constant.PXXM_TYPE1);
          }
          model.put("xqbean1", xqbean1);
          model.put("list1", list1);
          // 优秀班干部汇总
          List<RecommendStudentBean> list2 =
              getSchoolRecommendStudentList(gradeList, recommendStudentList, Constant.PXXM_TYPE4);
          Integer sum2 = 0;
          RecommendStudentBean xqbean2 = new RecommendStudentBean();
          if (!list2.isEmpty()) {
            for (RecommendStudentBean r2 : list2) {
              sum2 = sum2 + r2.getNjCount();
            }
            xqbean2 = new RecommendStudentBean();
            xqbean2.setXqCount(sum2);
            xqbean2.setXqmc(semester.getXqmc());
            xqbean2.setPxxm(Constant.PXXM_TYPE4);
          } else {
            xqbean2 = new RecommendStudentBean();
            xqbean2.setXqCount(0);
            xqbean2.setXqmc(semester.getXqmc());
            xqbean2.setPxxm(Constant.PXXM_TYPE4);
          }
          model.put("xqbean2", xqbean2);
          model.put("list2", list2);
          // 好学生汇总
          List<RecommendStudentBean> list3 =
              getSchoolRecommendStudentList(gradeList, recommendStudentList, Constant.PXXM_TYPE2);
          Integer sum3 = 0;
          RecommendStudentBean xqbean3 = new RecommendStudentBean();
          if (!list3.isEmpty()) {
            for (RecommendStudentBean r3 : list3) {
              sum3 = sum3 + r3.getNjCount();
            }
            xqbean3 = new RecommendStudentBean();
            xqbean3.setXqCount(sum3);
            xqbean3.setXqmc(semester.getXqmc());
            xqbean3.setPxxm(Constant.PXXM_TYPE2);
          } else {
            xqbean3 = new RecommendStudentBean();
            xqbean3.setXqCount(0);
            xqbean3.setXqmc(semester.getXqmc());
            xqbean3.setPxxm(Constant.PXXM_TYPE2);
          }
          model.put("xqbean3", xqbean3);
          model.put("list3", list3);
          // 行为达标生汇总
          List<RecommendStudentBean> list4 =
              getSchoolRecommendStudentList(gradeList, recommendStudentList, Constant.PXXM_TYPE3);
          Integer sum4 = 0;
          RecommendStudentBean xqbean4 = new RecommendStudentBean();
          if (!list4.isEmpty()) {
            for (RecommendStudentBean r4 : list4) {
              sum4 = sum4 + r4.getNjCount();
            }
            xqbean4 = new RecommendStudentBean();
            xqbean4.setXqCount(sum4);
            xqbean4.setXqmc(semester.getXqmc());
            xqbean4.setPxxm(Constant.PXXM_TYPE3);
          } else {
            xqbean4 = new RecommendStudentBean();
            xqbean4.setXqCount(0);
            xqbean4.setXqmc(semester.getXqmc());
            xqbean4.setPxxm(Constant.PXXM_TYPE3);
          }
          model.put("xqbean4", xqbean4);
          model.put("list4", list4);
          // 技能特长生汇总
          List<RecommendStudentBean> list5 =
              getSchoolRecommendStudentList(gradeList, recommendStudentList, Constant.PXXM_TYPE5);
          Integer sum5 = 0;
          RecommendStudentBean xqbean5 = new RecommendStudentBean();
          if (!list5.isEmpty()) {
            for (RecommendStudentBean r5 : list5) {
              sum5 = sum5 + r5.getNjCount();
            }
            xqbean5 = new RecommendStudentBean();
            xqbean5.setXqCount(sum5);
            xqbean5.setXqmc(semester.getXqmc());
            xqbean5.setPxxm(Constant.PXXM_TYPE5);
          } else {
            xqbean5 = new RecommendStudentBean();
            xqbean5.setXqCount(0);
            xqbean5.setXqmc(semester.getXqmc());
            xqbean5.setPxxm(Constant.PXXM_TYPE5);
          }
          model.put("xqbean5", xqbean5);
          model.put("list5", list5);
        } else {
          model.put("msg", "统计的信息未生成报表信息,无法完成数据汇总");
        }

      } else {
        model.put("msg", "您没权限访问该页面");
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "学生期末总结列表 recommendStudentSchoolReport [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return "semesterSummary/recommendStudentSchool_Report";

  }

  private static List<RecommendStudentBean> getSchoolRecommendStudentList(List<Grade> gradeList,
      List<RecommendStudent> recommendStudentList, String pxxm) {
    RecommendStudentBean subBean = null;
    RecommendStudentBean bean = null;
    List<RecommendStudentBean> subBeanList = null;
    List<RecommendStudentBean> beanList = new ArrayList<RecommendStudentBean>();
    for (Grade g : gradeList) {
      subBeanList = new ArrayList<RecommendStudentBean>();
      // 汇总班级人数及名单
      for (RecommendStudent r : recommendStudentList) {
        if (g.getNjid().intValue() == r.getNjid().intValue() && pxxm.equals(r.getPxxm())) {
          subBean = new RecommendStudentBean();
          subBean.setBjmc(r.getBjmc());
          subBean.setBjCount(r.getCout());
          subBean.setXm(r.getXm());
          subBean.setPxxm(pxxm);
          subBeanList.add(subBean);
        }
      }
      // 汇总年级人数
      Integer sum = 0;
      if (!subBeanList.isEmpty()) {
        for (RecommendStudentBean r2 : subBeanList) {
          sum = sum + r2.getBjCount();
        }
        bean = new RecommendStudentBean();
        bean.setNjmc(g.getNjmc());
        bean.setNjCount(sum);
        bean.setSubList(subBeanList);
      } else {
        bean = new RecommendStudentBean();
        bean.setNjmc(g.getNjmc());
        bean.setNjCount(0);
      }
      beanList.add(bean);
    }
    return beanList;
  }



}

